<template>
    <h2 style="text-align: center;">添加页面</h2>
    {{form}}
    <table class="table">
        <tr>
            <td>房型名称</td>
            <td class="form-inline">
                <input type="text" v-model="form.hname" class="form-control">
            </td>
        </tr>
        <tr>
            <td>售价</td>
            <td class="form-inline">
                <input type="text" v-model="form.hprice" class="form-control">
            </td>
        </tr>
        <tr>
            <td>面积</td>
            <td class="form-inline">
                <input type="text" v-model="form.hmianji" class="form-control">
            </td>
        </tr>
        <tr>
            <td>可入住人数</td>
            <td class="form-inline">
                <input type="text" v-model="form.hnum" class="form-control">
            </td>
        </tr>
        <tr>
            <td>房型介绍</td>
           <td class="form-inline">
                <input type="text" v-model="form.hintroduce" class="form-control">
            </td>
        </tr>
        <tr>
            <td colspan="2" style="text-align: center;">
                <button class="btn btn-warning" @click="add">添加</button>
            </td>
        </tr>
    </table>
</template>
<script setup lang="ts">
import { ref, reactive, onMounted } from 'vue';
import axios from 'axios';
import "bootstrap/dist/css/bootstrap.min.css"
import router from '@/router';

const form = reactive({
  "hname": "",
  "hprice": "",
  "hmianji": "",
  "hnum": "",
  "hintroduce": "",
  "hbed": true,
  "hbreakfast": true,
  "hupdown": true
})

const add = () => {
        if (form.hname == "") {
        alert("房间名不能为空");
        return;
    }
    if (form.hprice == "") {
        alert("价格不能为空");
        return;
    }
    if (form.hmianji == "") {
        alert("面积不能为空");
        return;
    }
        if (form.hnum == "") {
        alert("数量不能为空");
        return;
    }
    if (form.hintroduce == "") {
        alert("介绍不能为空");
        return;
    }
    axios.post("https://localhost:7013/api/Hotel/Add", form).then(res => {
        if (res.data > 0) {
            alert("添加成功");
            router.push("/showlsit");
        }
        else {
            alert("添加失败");
            return;
        }
    })

}

</script>